<!--组件-信号设置-->
<template>
  <div>

    <div class="row" v-if="param && param.isOpen != undefined">
      <div class="row acenter" @click="openClick(!param.isOpen)">
        <text class="font28 main-t1">{{T('信号设置')}}</text>
        <LImage class="arrow-image" :src="param.isOpen ? Config.img('xiala_blue_.png') : Config.img('xiala_blue.png')"></LImage>
      </div>
    </div>

    <div v-if="param && param.isOpen">

      <!--开仓信号-->
      <template v-if="param.openSignal != undefined">
        <VSwitc class="switc"
        v-model="param.openSignal" 
        :isEdit="param.isEdit && param.openSignalEdit" 
        :explain="openSignalTipe" 
        :title="T('启动信号')"
        @change="param.openSignalMap=undefined" />
        
        <div class="frame bg2" v-if="param.openSignal" @click="selectClick(param.openSignalEdit,'openSignalMap')">

          <template v-if="param.openSignalMap">
            <LImage v-if="param.openSignalMap.signalType=='priceWarn'" 
            class="img-logo" :src="Config.img('zidingyi.png')" />
            <LImage v-else class="img-logo" :src="Config.img('jiagejingbao.png')" />

             <template v-if="param.openSignalEdit">
              <text class="font28 text1 all">{{param.openSignalMap.signalName}}</text>
              <LImage class="arrow-right-image" :src="Config.img('youjin.png')"></LImage>
            </template>
            <template v-else>
              <text class="font28 text2 all">{{param.openSignalMap.signalName}}</text>
              <LImage class="arrow-right-image" :src="Config.img('youjin.png')"></LImage>
            </template>
          </template>

          <template v-else>
            <text class="font28 text2 all">{{T('请选择信号')}}</text>
            <LImage class="arrow-right-image" :src="Config.img('youjin.png')"></LImage>
          </template>
        </div>
      </template>
    </div>
  </div>
</template>

<script>


//功能
const weexFunction = weex.requireModule('WeexFunction');


import modal from "@/_js/modal";
import navigator from "@/_js/navigator"; 
import Config from "@/_js/config";
import broadcast from "@/_js/broadcast";

import I18N from "@/_i18n/i18n";
var T = I18N.t;

var normParam = { 
  'isOpen':true, //true 显示
  'isEdit':true, //true 可编辑

  'openSignal':false, //true 启用开仓信号
  'openSignalMap':undefined, //开仓信号
  'openSignalEdit':true, //true 可编辑

  'suspendSignal':false, //true 启用暂停信号
  'suspendSignalMap':undefined, //暂停信号
  'suspendSignalEdit':true, //true 可编辑
}

//组件
import VInput from "@/public/view/VInput.vue";
import VSwitc from "@/public/view/VSwitc.vue";
export default {

  components: {
    VInput,
    VSwitc,
  },

  model:{
    prop:"param",
    event:"change",
  },
  
  props:{
    param:Object,
  },

  watch: {
    param: {
      deep: false,
      handler (val, oldVal) {
        this.initParam(val);
      }
    }
  },
  
  data() {
    return {
      T:T,
      Config:Config,

      timeStamp:'', //当前时间戳

      openSignalTipe:T('启用了信号接管后，该策略将处于等待状态，直至接收到第一条信号后，该策略才会启动并执行开仓操作。如不使用信号，关闭该状态即可，策略将会立即启动。'),
      suspendSignalTipe:T('开启此选项。'),
    };
  },

  mounted(){

    this.initParam(this.param);
  },

  methods:{


    //初始化参数
    initParam(param){

      if (param == undefined || JSON.stringify(param) == '{}') {
        this.param = JSON.parse(JSON.stringify(normParam));
        this.$emit("change", this.param); 
      }
    },

    //检查
    checkError(){

      if (this.param.openSignal && !this.param.openSignalMap) {
        modal.toast(T("请选择开仓信号"));
        return true;
      }

      if (this.param.suspendSignal && !this.param.suspendSignalMap) {
        modal.toast(T("请选择暂停信号"));
        return true;
      }

      return false;
    },
    
    //获取参数
    getParam(){
      
      var signal = JSON.parse(JSON.stringify(this.param));

      signal['start'] =  this.param.openSignal 
      ? this.param.openSignalMap.signalId 
      : undefined;

      signal['suspend'] =  this.param.suspendSignal 
      ? this.param.suspendSignalMap.signalId 
      : undefined;

      return signal;
    },
    
    /********************************** 点击触发*/
    //展开点击
    openClick(isOpen){
      this.param.isOpen = isOpen;
    },

    //选着点击
    selectClick(edit, key) {
      if (!edit) return;

      var param = {};
      navigator.open('', 'up/SelectSignal', param);
      broadcast.subscribeOnce('SelectSignal', (signal)=>{
        this.param[key] = signal;
	      this.$forceUpdate()
      });
    }
  }
}
</script>


<style src="@/_css/style.css"></style>
<style scoped>
.arrow-image {
  width: 20px;
  height: 20px;
  margin-left: 20px;
  margin-right: 20px;
}
.arrow-right-image {
  width: 20px;
  height: 20px;
}

.switc {
  margin-top: 40px;
}

.frame{
  flex-direction: row;
  align-items: center;

  height: 88px;
  border-radius: 16px;

  border-width: 2px;
  border-color: transparent;

  padding-left: 20px;
  padding-right: 20px;

  margin-top: 20px;
}
.no {
  position:absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
}
.img-logo {
  width: 50px;
  height: 50px;
  margin-right: 10px;
}
</style>
